# -*- coding:utf-8 -*-
# Author:Ami
# @Time    : 2018/12/16 11:49

import time, threading

event = threading.Event()


def lighter():
    count = 0
    event.set()
    while True:
        if count > 5 and count < 10:  # 改成红灯
            event.clear()  # 把标志位清了
            print("红灯")
        elif count > 10:
            event.set()  # 变绿灯
            count = 0
        else:
            print("绿灯")
        time.sleep(1)
        count += 1


def car(name):
    while True:
        if event.is_set():  # 代表绿灯
            print("[%s]绿灯跑" % name)
            time.sleep(1)
        else:
            print("[%s]红灯停" % name)
            event.wait()
            print("绿灯了，走你%s" % name)


light = threading.Thread(target=lighter, )
light.start()

car1 = threading.Thread(target=car, args=("Tesla",))
car1.start()
